package com.opennews.openplatform.familyexpenseapi.jooq

import org.springframework.boot.autoconfigure.jooq.DefaultConfigurationCustomizer
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class JooqConfig {
    /**
     * [How to customize a jOOQ configuration injected using Spring Boot](https://blog.jooq.org/how-to-customise-a-jooq-configuration-that-is-injected-using-spring-boot/)
     * [Spring Boot DefaultConfigurationCustomizer](https://docs.spring.io/spring-boot/api/java/org/springframework/boot/autoconfigure/jooq/DefaultConfigurationCustomizer.html)
     *
     * **IMPORTANT!!!**
     * DO NOT TRY TO CREATE A NEW CONFIGURATION, AS THIS WILL REMOVE ALL DEFAULT EXISTING CONFIGURATIONS.
     * For example, transactions, logging, etc.
     * With a newly created configuration, you may find that `@Transactional` is NOT working.
     *
     * The best approach is to get the default configuration and add your custom listener.
     */
    @Bean
    fun configurationCustomizer(): DefaultConfigurationCustomizer {
        return DefaultConfigurationCustomizer { c ->
            c.setRecordListener(RecordListener(), UserRecordListener())
        }
    }
}